package bth.reconfs;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;

public class AlarmReceiver extends BroadcastReceiver
{

	public void onReceive(Context context, Intent intent)
	{
		if( intent.getAction() != null && intent.getAction().equals("android.intent.action.BOOT_COMPLETED") )
		{
			MainActivity.scheduleAlarm(context);
		}
		else
		{
			showNotification(context, "Conference Planned", "Tomorrow 2PM BTH C313A");
		}
	}

	public void showNotification(Context context, String title, String contentText)
	{
		NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
		.setSmallIcon(R.drawable.ic_launcher)
		.setContentTitle(title)
		.setTicker(title)
		.setContentText(contentText)
		.setContentIntent(PendingIntent.getActivity(context, 0, new Intent(context, MainActivity.class), 0))
		.setAutoCancel(true);

		Notification note = builder.build();
		note.defaults = Notification.DEFAULT_ALL;

		NotificationManager notif = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
		notif.notify(1, note);
	}
}